<?php
//模型
class MessageModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'message';
	}
	
	function get_list($arr,$page=1,$size=10){
		$where = ' 1 ';
		
		if(isset($arr['title']) && !empty($arr['title'])){
			$where .= " AND title like '%{$arr['title']}%' ";
		}
		if(isset($arr['date']) && !empty($arr['date'])){
			//$where .= " AND DATE_FORMAT(addtime,'%Y-%m-%d')='{$arr['date']}' ";
			$start = strtotime($arr['date']." 00:00:00");
			$end = $start + 60*60*24;
			$where .= " AND addtime >= '{$start}' AND addtime< '{$end}' ";
		}
		
		if(isset($arr['type'])){
			$where .= " AND `type`='{$arr['type']}' ";
		}
		
		if(isset($arr['user_id']) && !empty($arr['user_id'])){
			$where .= " AND `target_id`='{$arr['user_id']}' ";
		}
		
		
		
		
		$res = $this->_where_get_list($where,$page,$size);
		return $res;
	}
	
	function get_info($id){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where id='{$id}' limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row;
	}
	
	function get_fields($name){
		$info = $this->_field_get_info($name,'name');
		if(!$info){
			return false;
		}
		$this->load->model('System/DictFieldModel','DictFieldModel');
		$list = $this->DictFieldModel->getAll(array('dict_id'=>$info['id']));
		return $list;
	}
}

